package com.yztc.orangeentertainment.ui.main.subscribefragment.staritem.starnewsfragment;

import android.content.Context;

import com.yztc.orangeentertainment.bean.channalbean.ChannelTuijian;
import com.yztc.orangeentertainment.bean.channalbean.ListBean;
import com.yztc.orangeentertainment.bean.staritembean.NewsBean;
import com.yztc.orangeentertainment.config.SubscribeUrlConfig;
import com.yztc.orangeentertainment.http.SubscribeRetrofitService;

import java.util.ArrayList;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by My on 2016/10/8.
 */
public class NewsModle implements NewsContract.Modle {
    @Override
    public void getStarAll(String type, Map<String, String> params, final OnLoadNewsListener loadNewsListener, Context context) {
        Retrofit retrofit=new Retrofit.Builder().baseUrl(SubscribeUrlConfig.PATH.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Call<ChannelTuijian> call=retrofit.create(SubscribeRetrofitService.class).getStarNewsAll(type,params);
        call.enqueue(new Callback<ChannelTuijian>() {
            @Override
            public void onResponse(Call<ChannelTuijian> call, Response<ChannelTuijian> response) {
                if (response.isSuccessful()) {
                    loadNewsListener.onSuccess(response.body().getData().getList());
                }else {
                }
            }

            @Override
            public void onFailure(Call<ChannelTuijian> call, Throwable t) {
                loadNewsListener.onFailure((Exception) t);
            }
        });
    }
}
